<?php
/**
 * Minhlog 文件缓存类
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   Minh
 * @package    Minh_Cache
 * @copyright  Copyright (c) 2009-2010 Minh.Shu@gmail.com
 * @license    New BSD License
 * @author     Minh.Shu
 * @version    $Id: File.php 37 2010-05-10 16:20:47Z Minh.Shu $
 *
 */
class Minh_Cache_File
{

    /**
     * 缓存对象
     * @access private
     * @var
     */
    private static $_cache = null;

    /**
     * 缓存状态
     * @access private
     * @var boolean
     */
    private static $_cacheStatus = true;

    /**
     * 缓存时间
     * @access private
     * @var integer
     */
    private static $_lifeTime = 3600;

    /**
     * 设置页面缓存对象
     * @return object
     */
    public static function setCache ()
    {
        if (null === self::$_cache) {
            $cacheDir = APPLICATION_PATH . '/caches'; //缓存目录
            if (! file_exists($cacheDir)) {
                @mkdir($cacheDir, 0777);
            }
            $frontendOptions = array('caching' => self::$_cacheStatus, 'cache_id_prefix' => 'minhlog', 'lifeTime' => self::$_lifeTime, 'automatic_serialization' => true, 'automatic_cleaning_factor' => 1, 'ignore_user_abort' => true);
            $backendOptions = array('cache_dir' => $cacheDir);
            self::$_cache = Zend_Cache::factory('Output', 'File', $frontendOptions, $backendOptions);
        }
        return self::$_cache;
    }

    /**
     * 获取页面缓存对象
     * @return object
     */
    public static function getCache ()
    {
        return self::setCache();
    }

    /**
     * 设置缓存开关
     * @param boolean $status
     * @return void
     */
    public static function setCacheStatus ($status = true)
    {
        self::$_cacheStatus = (boolean) $status;
    }

    /**
     * 设置缓存时间方法
     * @param integer $seconds
     * @return void
     */
    public static function setCacheLifeTime ($seconds = 600)
    {
        self::$_lifeTime = (int) $seconds;
    }
}
